﻿// Copyright (C) 2014 Can Batu Erdem
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Specialized;
using System.Text;

namespace Cyrene.Strategy
{
    public class TextTableGeneratorStrategy : TableGeneratorStrategy
    {
        internal override string Generate(string header, NameValueCollection nameValueCollection)
        {
            return GenerateTableHeader(header) + GenerateTableContent(nameValueCollection) + GenerateTableFooter();
        }

        internal override string GenerateTableHeader(string header)
        {
            return string.Format("|||||||||| {0} ||||||||||", header) + Environment.NewLine;
        }

        internal override string GenerateInlineHeader(string header)
        {
            return string.Format("---------- {0} ----------", header) + Environment.NewLine;
        }

        internal override string GenerateTableContent(NameValueCollection nameValueCollection)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < nameValueCollection.Count; i++)
            {
                sb.AppendLine(string.Format("{0}: {1}", nameValueCollection.Keys[i], nameValueCollection[i]));
            }
            return sb.ToString();
        }

        internal override string GenerateTableContentSingleColumn(string[] lines)
        {
            StringBuilder sb = new StringBuilder();
            foreach (string l in lines)
            {
                sb.AppendLine(l);
            }
            return sb.ToString();
        }

        internal override string GenerateTableFooter()
        {
            return Environment.NewLine;
        }
    }
}
